package com.young.springdemo.service.statePattern;

//账户类 充当环境类
public class Account {
    private AccountState state;//维持一个对抽象状态的引用
    private String owner;//开户姓名
    private double balance = 0 ;//账户余额


    public Account(String owner, double init) {
        this.owner = owner;
        this.state = new NormalAccountState(this); //账户设置初始状态
        System.out.println(this.owner+"开户了,初始金额为"+init);
        this.balance = init;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void setState(AccountState state) {
        this.state = state;
    }

    public void deposit(double amount){
        state.deposit(amount);
        System.out.println("存款"+amount+"后,现在账户余额为:"+balance);
    }

    public void withdraw(double amount){
        state.withdraw(amount);
        System.out.println(
                "取款"+amount+"后,现在账户余额为"+balance
        );
    }
    public void computerInterest(){
        state.computerInterest();
    }
}
